package com.anjubao.parking.municipal.user.form;

import com.anjubao.parking.municipal.common.exception.ServiceException;
import com.anjubao.parking.municipal.user.constants.BalanceTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

/**
 * 余额充值
 *
 * @author zhuchunfeng
 * @date 2019/6/20 11:09
 */
@Data
public class UserBalancePayForm {
    /**
     * userCode : 20190617111124575
     * amount : 500
     * type : 1
     */
    @ApiModelProperty(value = "订单id",required = true)
    private String tradeOrderId;

    @ApiModelProperty(value = "16位用户编号", required = true)
    private String userCode;

    @ApiModelProperty(value = "充值金额 单位分", required = true)
    private int amount;

    @ApiModelProperty(value = "1:充值 2:消费", required = true)
    private Integer type;

    @ApiModelProperty(value = "停车记录id,充值为空,")
    private String recodeId;

    public void validate() {
        if (StringUtils.isEmpty(userCode)) {
            throw new ServiceException("userCode不能为空");
        }
        if (amount <= 0) {
            throw new ServiceException("金额不能小于0");
        }
        if (!BalanceTypeEnum.exist(type)) {
            throw new ServiceException("type 有误");
        }
        if (StringUtils.isEmpty(recodeId) && BalanceTypeEnum.CONSUME.getCode().equals(type)) {
            throw new ServiceException("消费时 recodeId不能为空");
        }
    }

}
